import {mapState} from 'vuex'

export const shipMixin = {
  data() {
    return {
      shipId: null,
      t: null,
      time: 5 // 几分钟
    }
  },
  computed: {
    ...mapState('bigScreen', [
      'shipInfo'
    ])
  },
  mounted() {
    this.$nextTick(() => {
      this.shipChange()
      this.t = setInterval(() => {
        this.shipChange()
      }, this.time * 1000 * 60)
    })
  },
  beforeDestroy() {
    clearInterval(this.t)
    this.t = null
  },
  watch: {
    shipInfo: {
      handler() {
        // 如果是搜索过来的
        if (this.shipInfo.flag) {
          this.shipId = this.shipInfo.shipId
        } else {
          if (this.shipId !== this.shipInfo.shipId) {
            this.shipId = this.shipInfo.shipId
          } else {
            this.shipId = null
          }
        }
        this.shipChange()
      },
      deep: true
    }
  },
  methods: {
    shipChange() {
    }
  }
}
